home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / BoxMaker++ / Monochromize ƒ / gworld.cp < prev    next >
Encoding:
Text File  |  1995-01-20  |  2.1 KB  |  81 lines  |  [TEXT/KAHL]

  1. #include <stdlib.h>
  2.  
  3. #include <Windows.h>
  4. #include <QDOffscreen.h>
  5. #include <Memory.h>
  6. #include <Fonts.h>
  7. #include <Packages.h>
  8. #include <SegLoad.h>
  9. #include <ToolUtils.h>
  10. #include <TextEdit.h>
  11. #include <Files.h>
  12.  
  13. #include "grafport.h"
  14. #include "gworld.h"
  15.  
  16. gworld::gworld( int breedte, int hoogte, int diepte, CTabHandle cTable)
  17. {
  18.     if( (diepte != 1) && (diepte !=  2) && (diepte !=  4)
  19.         && (diepte != 8) && (diepte != 16) && (diepte != 32))
  20.     {
  21.         DebugStr( "\pgworld::gworld: illegal depth passed");
  22.         exit( EXIT_FAILURE);
  23.     }
  24.     if( (hoogte <= 0) || (breedte <= 0))
  25.     {
  26.         DebugStr( "\pgworld::gworld: illegal width and/or height passed");
  27.         exit( EXIT_FAILURE);
  28.     }
  29.     myRect.top    = 0;
  30.     myRect.left   = 0;
  31.     myRect.bottom = hoogte;
  32.     myRect.right  = breedte;
  33.     
  34.     de_diepte     = diepte;
  35.     
  36.     if( NewGWorld( &myGWorldPtr, de_diepte, &myRect, cTable, nil, 0) != noErr)
  37.     {
  38.         //
  39.         // retry in temporary memory. We do not set the 'AllowPurgePixels' bit.
  40.         // This is not the proper thing to do, but doing it this way is better than
  41.         // failing immediately.
  42.         //
  43.         (void)NewGWorld( &myGWorldPtr, de_diepte, &myRect, cTable, nil, useTempMem);
  44.     }
  45.     myGDHandle = GetGWorldDevice( myGWorldPtr);
  46.     
  47.     const PixMapHandle myPixMapH = GetGWorldPixMap( myGWorldPtr);
  48.  
  49.     (void)LockPixels( myPixMapH);
  50.  
  51.     HLock( (Handle)myPixMapH); 
  52.         
  53.     myPix = (*myPixMapH);
  54. }
  55.  
  56. gworld::~gworld()
  57. {
  58.     const PixMapHandle myPixMapH = GetGWorldPixMap( myGWorldPtr);
  59.     HUnlock( (Handle)myPixMapH);
  60.     UnlockPixels( myPixMapH);
  61.     DisposeGWorld( myGWorldPtr);
  62. }
  63.  
  64. OSErr gworld::dump( short defile) const
  65. {
  66.     const int rowChars = (myPix->rowBytes & 0x2FFF);
  67.     const int numRows   = myPix->bounds.bottom - myPix->bounds.top;
  68.     long totalChars = rowChars * numRows;
  69.     const void *curAddress = (const void *)myPix->baseAddr;
  70.     return FSWrite( defile, &totalChars, curAddress);
  71. }
  72.  
  73. OSErr gworld::load( short defile) const
  74. {
  75.     const int rowChars = (myPix->rowBytes & 0x2FFF);
  76.     const int numRows   = myPix->bounds.bottom - myPix->bounds.top;
  77.     long totalChars = rowChars * numRows;
  78.     void *curAddress = (void *)myPix->baseAddr;
  79.     return FSRead( defile, &totalChars, curAddress);
  80. }
  81.